var path="http://localhost:8080/";

Vue.component('jx-topbar',{
    template:`
  <div class="header section">

        <!-- Header Top Start -->
        <div class="header-top bg-name-primary">
            <div class="container">
                <div class="row align-items-center">

                    <!-- Header Top Message Start -->
                    <div class="col-12 col-lg-6">
                        <div class="header-top-msg-wrapper">
                            <p class="header-top-message">找会议 来聚星</p>
                        </div>
                    </div>
                    <div class="col-12 col-lg-6">
                        <div class="header-top-settings">
                            <ul class="nav">
                                <li v-show="logANDres">
                                <a href="#" @click.prevent="userLogin">登录</a>
                                &nbsp&nbsp|&nbsp&nbsp 
                                <a href="#" @click.prevent="userRegister">注册</a>
                                </li>
                                <li v-show="member" class="curreny-wrap">
                                    <a href="#"><span>{{name}}</span></a>
                                    <i class="fa fa-angle-down"></i>
                                    <ul class="dropdown-list curreny-list">
                          
                                        <li><a href="#" @click.prevent="logout">退出</a></li>

                                    </ul>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <!-- Header Top Message End -->

                </div>
            </div>
        </div>
        <!-- Header Top End -->

        <!-- Header Bottom Start -->
        <div class="header-bottom">
            <div class="header-sticky">
                <div class="container">
                    <div class="row align-items-center position-relative">

                        <!-- Header Logo Start -->
                        <div class="col-lg-3 col-md-4 col-6">
                            <div class="header-logo">
                                <a href="index.html"><img src="../../../resources/static/images/logo.png" alt="Site Logo" /></a>
                            </div>
                        </div>
                        <!-- Header Logo End -->

                        <!-- Header Menu Start -->
                        <div class="col-lg-6 d-none d-lg-block">
                            <div class="main-menu">
                                <ul>
                                    <li class="has-children">
                                        <a href="#">主页</a>
                                        <ul class="sub-menu">
                                            <li><a href="index.html">Home 1</a></li>
                                            <li><a href="index-2.html">Home 2</a></li>
                                            <li><a href="index-3.html">Home 3</a></li>
                                            <li><a href="index-4.html">Home 4</a></li>
                                        </ul>
                                    </li>
                                    <li class="has-children position-static">
                                        <a href="#">分类</a>
                                        <ul class="mega-menu">
                                            <li class="mega-menu-col">
                                                <h4 class="mega-menu-title">Shop Layout</h4>
                                                <ul class="m-b-n10">
                                                    <li><a href="shop.html">Shop Grid</a></li>
                                                    <li><a href="shop-left-sidebar.html">Left Sidebar</a></li>
                                                    <li><a href="shop-right-sidebar.html">Right Sidebar</a></li>
                                                    <li><a href="shop-list-fullwidth.html">List Fullwidth</a></li>
                                                    <li><a href="shop-list-left-sidebar.html">List Left Sidebar</a></li>
                                                    <li><a href="shop-list-right-sidebar.html">List Right Sidebar</a></li>
                                                </ul>
                                            </li>
                                            <li class="mega-menu-col">
                                                <h4 class="mega-menu-title">分类1</h4>
                                                <ul class="m-b-n10">
                                                    <li><a href="single-product.html">Single Product</a></li>
                                                    <li><a href="single-product-sale.html">Single Product Sale</a></li>
                                                    <li><a href="single-product-variable.html">Single Product Variable</a></li>
                                                    <li><a href="single-product-countdown.html">Single Product Countdown</a></li>
                                                    <li><a href="single-product-affiliate.html">Single Product Affiliate</a></li>
                                                    <li><a href="single-product-slider.html">Single Product Slider</a></li>
                                                </ul>
                                            </li>
                                            <li class="mega-menu-col">
                                                <h4 class="mega-menu-title">分类2</h4>
                                                <ul class="m-b-n10">
                                                    <li><a href="my-account.html">My Account</a></li>
                                                    <li><a href="login.html">Login | Register</a></li>
                                                    <li><a href="wishlist.html">Wishlist</a></li>
                                                    <li><a href="cart.html">Cart</a></li>
                                                    <li><a href="checkout.html">Checkout</a></li>
                                                    <li><a href="compare.html">Compare</a></li>
                                                </ul>
                                            </li>
                                            <li class="mega-menu-col">
                                                <div class="megamenu-image">
                                                    <a href="shop.html">
                                                        <img class="fit-image" src="../../../resources/static/header/assets/images/header/mega-menu.png" alt="Megamenu Image">
                                                    </a>
                                                </div>
                                            </li>
                                        </ul>
                                    </li>
                                    <li class="has-children">
                                        <a href="#">分类</a>
                                        <ul class="sub-menu">
                                            <li><a href="about.html">分类3</a></li>
                                            <li><a href="contact.html">Contact Us</a></li>
                                            <li><a href="error-404.html">Error 404</a></li>
                                            <li><a href="faq.html">FAQ</a></li>
                                            <li><a href="login.html">Login</a></li>
                                            <li><a href="register.html">Register</a></li>
                                        </ul>
                                    </li>
                                    <li class="has-children">
                                        <a href="#">分类</a>
                                        <ul class="sub-menu">
                                            <li><a href="blog.html">Blog</a></li>
                                            <li><a href="blog-left-sidebar.html">Blog Left Sidebar</a></li>
                                            <li><a href="blog-right-sidebar.html">Blog Right Sidebar</a></li>
                                            <li><a href="blog-details.html">Blog Details</a></li>
                                            <li><a href="blog-details-sidebar.html">Blog Details Sidebar</a></li>
                                        </ul>
                                    </li>
                                    <li><a href="about.html">分类4</a></li>
                                    <li><a href="javascript:void(0)" @click="release">免费发布活动</a></li>
                                </ul>
                            </div>
                        </div>
                        <!-- Header Menu End -->

                        <!-- Header Action Start -->
                        <div class="col-lg-3 col-md-8 col-6">
                            <div class="header-actions">

                                <!-- Header Action Search Button Start -->
                                <div class="header-action-btn header-action-btn-search d-none d-md-flex">
                                   <!--搜索--> 
                                    <div v-show="search1" @click="search11" class="action-execute">
                                        <a class="action-search-open" href="javascript:void(0)"><i  class="icon-magnifier icons"></i></a>
                                        <a class="action-search-close" href="javascript:void(0)"><i class="ti-close"></i></a>
                                    </div>
                                    
                                    <div v-show="search2" @click="search22" class="action-execute visible-execute">
                                        <a class="action-search-open" href="javascript:void(0)"><i  class="icon-magnifier icons"></i></a>
                                        <a class="action-search-close" href="javascript:void(0)"><i class="ti-close"></i></a>
                                    </div>
                                    <!-- Search Form and Button Start -->
                                    
                                    <!--搜索-->
                                    
                                    <form v-show="search3" class="header-search-form visible-execute" action="#">
                                        <input type="text" class="header-search-input" placeholder="Search Our Store">
                                        <button class="header-search-button"><i  class="icon-magnifier icons"></i></button>
                                    </form>
                                    <!-- Search Form and Button End -->
                                </div>
                                <!-- Header Action Search Button End -->

                                <!-- Header My Account Button Start -->
                                <a href="javascript:void(0)" @click.prevent="personal" class="header-action-btn header-action-btn-wishlist">
                                    <i class="icon-user icons"></i>
                                </a>
                                <!-- Header My Account Button End -->

                                <!-- Header Action Button Start -->
                              
                                <div class="header-action-btn header-action-btn-cart d-flex d-sm-none">
                                    <a href="cart.html">
                                        <i class="icon-handbag icons"></i>
                                        <span class="header-action-num">3</span>
                                    </a>
                                </div>
                                <!-- Header Action Button End -->

                                <!-- Mobile Menu Hambarger Action Button Start -->
                                <a href="javascript:void(0)" class="header-action-btn header-action-btn-menu d-lg-none d-md-flex">
                                    <i class="icon-menu"></i>
                                </a>
                                <!-- Mobile Menu Hambarger Action Button End -->

                            </div>
                        </div>
                        <!-- Header Action End -->

                    </div>
                </div>
            </div>
        </div>
        <!-- Header Bottom End -->

    </div>
    `,
    data:function(){
        return{
            name:"",
            logANDres:"",
            member:"",
            search1:true,
            search2:false,
            search3:false,
            searchBtn:true


        }
    },
    created:function(){
            this.login();
    },
    methods:{
        login:function(){
            //登录检查
            var token = sessionStorage.getItem("token");

            if(token!=null)
            {
                this.member=true;
                var userAccount=sessionStorage.getItem("userAccount")

                this.name=userAccount;
            }
            else
            {
                this.logANDres=true;
                this.member=false;
            }

//如果没有登录转到登录页面，把当前页面的路径作为参数传递给登录
            if(!token){
                var url = window.location.href;
                //window.location.href="login.html?url="+url;
            }

//axios发送请求时，在请求头中携带token
            axios.defaults.headers.common["token"]=token;



//添加响应拦截器，当token过期登录失败时，直接跳转到登录页面
//否则，如果不加该统一处理响应的拦截器，则每个ajax的方法都应该单独处理，
//如果不处理,比如请求/questionType/list.html就会看不到任何数据，响应信息为token验证失败
            axios.interceptors.response.use(function(res){
                console.log("请求之后............")
                var code = res.data.code;
                if(code==99999){
                    var url = window.location.href;
                    //if(url.indexOf("/login.html")==-1)
                    {
                        window.location.href="login.html?url="+url;
                    }
                }
                else{
                    return res;
                }
            },function(error){
                //对错误进行处理
                return Promise.reject(error);
            });

        },

    userLogin:function () {
        location.href="login.html";
    },
    userRegister:function () {
        location.href="register.html";
    },
        search11:function () {
        this.search1=false;
        this.search2=true;
        this.search3=true;
        },
        search22:function () {

            this.search1=true;
            this.search2=false;
            this.search3=false;
        },
        personal:function () {
            var token=sessionStorage.getItem("token");
            if(token==null)
            {
                location.href="login.html";
            }
            else {
                location.href="my-account.html"
            }
        },
        logout:function () {
            sessionStorage.removeItem("token");
            location.href="index.html";
        },
        release:function () {
            var token=sessionStorage.getItem("token");
            if(token==null)
            {
                location.href="login.html";
            }
            else {
                location.href="cheakout.html"
            }
        }



    }


})